package com.wing.invLocaltion.controller;

import com.wing.common.exception.BusinessException;
import com.wing.common.utils.JsonResult;
import com.wing.invLocaltion.entity.request.InvLocationCreateRequest;
import com.wing.invLocaltion.entity.request.InvLocationQueryRequest;
import com.wing.invLocaltion.service.InvLocationService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 畅捷通-货位管理2
 *
 * @author xiayang
 */
@Validated
@Api(value = "畅捷通-货位管理", tags = "#/chanjet/invLocation")
@RestController("chanjetInvLocationController")
@RequestMapping("invLocation/admin/invLocation")
@RequiredArgsConstructor

public class InvLocationController {

    @Resource
    InvLocationService invLocationService;

    /**
     * 货位查询2
     */
    @PostMapping("/query")
    public JsonResult query(@RequestParam(name = "code") String code) {
        InvLocationQueryRequest request = new InvLocationQueryRequest();
        if(StringUtils.isNotEmpty(code)){
            request.setCode(code);
        }
        return JsonResult.success(invLocationService.invLocationQuery(request));
    }

    /**
     * 货位创建
     */
    @PostMapping("/create")
    public JsonResult create(@RequestBody InvLocationCreateRequest invLocationCreateRequest) {
        try {
            return invLocationService.invLocationCreate(invLocationCreateRequest);
        } catch (BusinessException e) {
            return JsonResult.fail(e.getMessage());
        }
    }

}
